// client.js
import axios from './axios'
const config = require('../../config')

let client = {
  async post(url, params, headers) {
    let postHeaders = Object.assign({ 'Content-Type': 'application/json' }, headers)
    try {
      let res = await axios.post(url, params, { headers: postHeaders })
      // console.log(res)
      let resData = { ...res.data, headers: res.headers }
      if (res.success) {
        return Promise.resolve(resData)
      } else {
        return Promise.reject(resData)
      }
    } catch (err) {
      return Promise.reject(err)
    }
  },
  async get(url, params, headers) {
    let postHeaders = Object.assign({}, headers)
    try {
      let res = await axios.get(url, params, { headers: postHeaders })
      // console.log(res)
      let resData = { ...res.data, headers: res.headers }
      if (res.success) {
        return Promise.resolve(resData)
      } else {
        return Promise.reject(resData)
      }
    } catch (err) {
      return Promise.reject(err)
    }
  }
}

module.exports = client
